package com.aloda.controller.user;

import com.aloda.dto.UserLoginDTO;
import com.aloda.dto.UserPageByTagDTO;
import com.aloda.dto.UserRegisterDTO;
import com.aloda.dto.UserSetDTO;
import com.aloda.result.Result;
import com.aloda.service.UserService;
import com.aloda.vo.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户端用户controller
 */
@Slf4j
@RestController("userController")
@Tag(name = "客户端用户相关接口")
@RequestMapping("/user/user")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 用户注册
     * @param userRegisterDTO
     * @return
     */
    @Operation(summary = "用户注册")
    @PostMapping("/register")
    public Result userRegister(@RequestBody UserRegisterDTO userRegisterDTO) {
        log.info("用户注册：{}",userRegisterDTO);
        userService.userRegister(userRegisterDTO);
        return Result.success();
    }

    /**
     * 用户登录
     * @param userLoginDTO
     * @return
     */
    @Operation(summary = "用户登录")
    @PostMapping("/login")
    public Result<UserLoginVO> userLogin(@RequestBody UserLoginDTO userLoginDTO) {
        log.info("用户登录：{}",userLoginDTO);
        UserLoginVO userLoginVO = userService.userLogin(userLoginDTO);
        return Result.success(userLoginVO);
    }

    /**
     * 用户退出
     * @return
     */
    @Operation(summary = "用户退出")
    @PostMapping("/logout/{token}")
    public Result userLogout(@PathVariable String token) {
        log.info("用户退出：{}",token);
        userService.userLogout(token);
        return Result.success();
    }

    /**
     * 获取用户主页信息
     * @return
     */
    @Operation(summary = "获取用户主页信息")
    @GetMapping("/info")
    public Result<UserInfoVO> getUserPageInfo() {
        UserInfoVO userInfoVO = userService.getUserPageInfo();
        return Result.success(userInfoVO);
    }

    /**
     * 获取用户设置页信息
     * @return
     */
    @Operation(summary = "获取用户设置页信息")
    @GetMapping("/set")
    public Result<UserSetVO> getUserSetInfo() {
        UserSetVO userSetVO = userService.getUserSetInfo();
        return Result.success(userSetVO);
    }

    /**
     * 用户修改基本信息
     * @return
     */
    @Operation(summary = "修改基本信息")
    @PostMapping("/set")
    public Result updateUserInfo(@RequestBody UserSetDTO userSetDTO) {
        log.info("用户修改基本信息:{}",userSetDTO);
        userService.updateUserInfo(userSetDTO);
        return Result.success();
    }

    /**
     * 获取用户所有标签
     * @return
     */
    @Operation(summary = "获取用户标签")
    @GetMapping("/tag")
    public Result<List<TagSimpleVO>> getTags() {
        List<TagSimpleVO> tags = userService.getUserTagList();
        return Result.success(tags);
    }

    /**
     * 用户修改自己的标签
     * @return
     */
    @Operation(summary = "修改用户标签")
    @PutMapping("/tag")
    public Result updateTags(@RequestBody List<String> tags) {
        userService.updateUserTags(tags);
        return Result.success();
    }

    /**
     * 根据标签查询用户
     * @return
     */
    @Operation(summary = "根据标签查询用户")
    @PostMapping("/tag/search")
    public Result<List<UserSearchVO>> queryUsersByTags(@RequestBody UserPageByTagDTO userPageByTagDTO) {
        List<UserSearchVO> list = userService.searchUsersByTags(userPageByTagDTO);
        return Result.success(list);
    }
}
